package com.lagou.redis;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

import java.util.HashSet;
import java.util.Set;

/**
 * created by wq at 2020/12/3
 */
public class RedisClusterTest {
    public static void main(String[] args) {
        JedisPoolConfig config = new JedisPoolConfig();
        Set<HostAndPort> clusterNodes = new HashSet<>();
        clusterNodes.add(new HostAndPort("192.168.73.128", 7001));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7002));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7003));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7004));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7005));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7006));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7007));
        clusterNodes.add(new HostAndPort("192.168.73.128", 7008));
        JedisCluster client = new JedisCluster(clusterNodes, 60000, config);
        for (int i = 0; i < 10; i++) {
            String key = String.format("key%d", i);
            String value = String.format("value%d", i);
            client.set(key, value);
        }
        for (int i = 0; i < 10; i++) {
            String key = String.format("key%d", i);
            String value = client.get(key);
            System.out.println(key + ":" + value);
        }
    }
}
